﻿@page "/login"
@layout EmptyLayout

<div style="position: fixed; top: 0; left: 0; right: 0; z-index: 9999;">
    @if (IsLoginFailed)
    {
        <Alert Type="AlertType.Warning"
               Message="登录失败，请检查您的用户名和密码。"
               Banner
               Closable
               OnClose="() => CloseAlert()" />
    }
</div>

<div style="text-align: center;">
    <Card Bordered="true" Title=@("用户登录") Style="width: 400px; margin: 0 auto;" Hoverable="true">
        <Login IsLoginFailed="@IsLoginFailed" OnLoginFailed="HandleLoginFailed"></Login>
        <Space Direction="SpaceDirection.Vertical" Style="width: 100%;">
            <SpaceItem>
                <div>
                    <a href="register">注册账户</a>
                </div>
            </SpaceItem>
        </Space>
    </Card>
</div>

@code {
    private bool IsLoginFailed { get; set; } = false;

    // 处理子组件触发的登录失败事件
    private void HandleLoginFailed()
    {
        IsLoginFailed = true; // 更新状态以显示 Alert
    }

    private void CloseAlert()
    {
        IsLoginFailed = false;
    }

}